﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using Web.UI;
namespace Web.admin
{
    public partial class center :ManagePage
    {
        BLL.WebLog log = new BLL.WebLog();
        BLL.NewsContent newsContent = new BLL.NewsContent();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                /*
                lb_bind();
                lb_tools_bind();
                manage_news_bind();
                */
            }

        }
        /// <summary>
        /// 得到最后两次登录列表，并将相应的内容绑定到相应的label上
        /// </summary>
        protected void lb_bind() 
        {
            DataTable dt = log.getLogRows(2, "WbUserName = '" + Session["AdminName"].ToString() + "'", " order by WbAddTime desc");
          lb_ip_now.InnerText = dt.Rows[0]["WbIpAddress"].ToString();
          if (dt.Rows.Count>1)
          {
              lb_time_last.InnerText = dt.Rows[1]["WbAddTime"].ToString();
              lb_ip_last.InnerText = dt.Rows[1]["WbIpAddress"].ToString();
          }
          else
          {
              lb_time_last.InnerText = "无";
              lb_ip_last.InnerText = "无";
          }
        }
        /// <summary>
        /// lb_tools绑定
        /// </summary>
        protected void lb_tools_bind() 
        {
            StringBuilder sbd = new StringBuilder();
            string permissionStr = string.Empty;
            if (Session["AdminPermission"] != null && Session["AdminPermission"].ToString() != "")
                permissionStr = new DbCommon.DbHelper().GetSingleItem("UserClass", "UserPermission", "UserId=" + Session["AdminPermission"].ToString()).ToString();
            string[] strArry = DbCommon.Utils.SplitString(permissionStr, ',');
            foreach (string str in strArry) {
                if (str == "3")
                    sbd.Append("<a href='#'  class='permission_btn'><span><b class='publish'>信息管理</b></span></a>");
                if(str=="1")
                    sbd.Append("<a href='#'  class='permission_btn'><span><b class='contest'>竞赛管理</b></span></a>");
                if(str=="2")
                    sbd.Append("<a href='#'  class='permission_btn'><span><b class='students'>学生管理</b></span></a>");
                if(str=="3")
                    sbd.Append("<a href='#'  class='permission_btn'><span><b class='user'>用户管理</b></span></a>");
                if(str=="4")
                    sbd.Append("<a href='#'  class='permission_btn'><span><b class='log'>系统管理</b></span></a>"); 
            }
            lb_tools.InnerHtml = sbd.ToString();
        }
        /// <summary>
        /// 绑定manage_news
        /// </summary>
        protected void manage_news_bind() 
        {
            DataTable dt = newsContent.GetRows(1, "NewsClassId=15", "order by NewspubTime desc");
            if (dt.Rows.Count > 0)
            {
                manage_news.InnerText = dt.Rows[0]["NewsArticle"].ToString();
            }
            else
                manage_news.InnerText = "后台暂无消息";
        }
    }
}